﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using MVCPets.Extensions;

namespace MVCPets.Tests.Extensions
{
  [TestClass]
  public class ValidationExtensions
  {
    [TestMethod]
    public void Test_IsAlpha()
    {
      Assert.IsTrue("A".IsAlpha());
      Assert.IsFalse("1".IsAlpha());
    }

    [TestMethod]
    public void Test_IsAlphaNumeric()
    {
      Assert.IsTrue("A".IsAlphaNumeric());
      Assert.IsTrue("1".IsAlphaNumeric());
      Assert.IsTrue("A1".IsAlphaNumeric());
      Assert.IsFalse("^".IsAlphaNumeric());


      Assert.IsTrue("A ".IsAlphaNumeric(true));
      Assert.IsTrue("1 ".IsAlphaNumeric(true));
      Assert.IsTrue("A1 ".IsAlphaNumeric(true));
      Assert.IsFalse("^ ".IsAlphaNumeric(true));

      Assert.IsFalse("A ".IsAlphaNumeric(false));
      Assert.IsFalse("1 ".IsAlphaNumeric(false));
      Assert.IsFalse("A1 ".IsAlphaNumeric(false));
      Assert.IsFalse("^ ".IsAlphaNumeric(false));
    }

    [TestMethod]
    public void Test_IsNumeric()
    {
      Assert.IsFalse("^ ".IsNumeric());
      Assert.IsFalse("1A".IsNumeric());
      Assert.IsTrue("1".IsNumeric());

      Assert.IsFalse("^ ".IsNumeric());
      Assert.IsFalse("1A".IsNumeric());
      Assert.IsTrue("1".IsNumeric());
    }

    [TestMethod]
    public void Test_IsEmail()
    {
      Assert.IsTrue("A@A.com".IsEmail());
      Assert.IsFalse("bob".IsEmail());
    }

    [TestMethod]
    public void Test_IsLowerCase()
    {
      Assert.IsTrue("a".IsLowerCase());
      Assert.IsFalse("A".IsLowerCase());
    }

    [TestMethod]
    public void Test_IsUpperCase()
    {
      Assert.IsTrue("A".IsUpperCase());
      Assert.IsFalse("a".IsUpperCase());
    }

    [TestMethod]
    public void Test_IsGUID()
    {
      Assert.IsTrue(Guid.NewGuid().ToString().IsGuid());
      Assert.IsFalse("a".IsGuid());
    }

    [TestMethod]
    public void Test_Is_Zip()
    {
      Assert.IsTrue("74125".IsZIPCodeFive());
      Assert.IsFalse("74125-1204".IsZIPCodeFive());

      Assert.IsTrue("74125-1204".IsZIPCodeFivePlusFour());
      Assert.IsFalse("74125".IsZIPCodeFivePlusFour());

      Assert.IsTrue("74125".IsZIPCodeAny());
      Assert.IsTrue("74125-1204".IsZIPCodeAny());
      Assert.IsFalse("74125+1204".IsZIPCodeAny());
      Assert.IsFalse("7412A".IsZIPCodeAny());
    }

    [TestMethod]
    public void Test_Is_Social()
    {
      Assert.IsTrue("123456789".IsSocialSecurityNumber());
      Assert.IsTrue("123-45-6789".IsSocialSecurityNumber());
      Assert.IsFalse("1234567890".IsSocialSecurityNumber());
      Assert.IsFalse("12345678".IsSocialSecurityNumber());
    }

    [TestMethod]
    public void Test_Is_Ip()
    {
      Assert.IsTrue("127.0.0.1".IsIPAddress());
      Assert.IsFalse("127.0.0.".IsIPAddress());
      Assert.IsFalse("127.0.0.A".IsIPAddress());
    }

    [TestMethod]
    public void Test_Is_Phone()
    {
      Assert.IsTrue("(865)123-1234".IsUSTelephoneNumber());
      Assert.IsTrue("(865) 123-1234".IsUSTelephoneNumber());
      Assert.IsTrue("865-123-1234".IsUSTelephoneNumber());
      Assert.IsTrue("8651231234".IsUSTelephoneNumber());
      Assert.IsFalse("865123234".IsUSTelephoneNumber());
      Assert.IsFalse("865123234A".IsUSTelephoneNumber());
      Assert.IsFalse("86512323455".IsUSTelephoneNumber());
    }

    [TestMethod]
    public void Test_IsCurrency()
    {
      Assert.IsTrue("$1.10".IsUSCurrency());
      Assert.IsTrue("$.10".IsUSCurrency());
      Assert.IsTrue("$10".IsUSCurrency());
      Assert.IsTrue("$10,124.12".IsUSCurrency());
      Assert.IsFalse("A8".IsUSCurrency());
    }

    [TestMethod]
    public void Test_IsURl()
    {
      Assert.IsTrue("http://www.google.com".IsURL());
      Assert.IsTrue("http://www.google.com/Test".IsURL());
      Assert.IsTrue("http://www.google.com/Test.html".IsURL());
      Assert.IsTrue("http://google.com/Test.html".IsURL());
      Assert.IsTrue("http://google.org/Test.html".IsURL());
      Assert.IsFalse("kitten".IsURL());
    }

    [TestMethod]
    public void Test_Is_Strong_Password()
    {
      Assert.IsTrue("2346786asdfdsfal;sdKJ:LKJ".IsStrongPassword());
      Assert.IsFalse("kitten".IsStrongPassword());
    }
  }
}
